//
//  GLSettingViewController.m
//  GLFormKitDemo
//
//  Created by 121 on 2018/3/28.
//  Copyright © 2018年 杭州吉利控股信息中心. All rights reserved.
//

#import "GLSettingViewController.h"
#import "GLCustomCell.h"
#import "GLCustomCellHelper.h"

@interface GLSettingViewController ()<GLCustomCellDelegate>{
    NSArray* _myData;
}

@end

@implementation GLSettingViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    [self configData];
    self. form = [self getFormData];
    
    
}


- (void)formRowClicked:(GLFormRow *)row{
    [super formRowClicked:row];
    
    if (self.index == 0) {
        GLSettingViewController* ctl = [[GLSettingViewController alloc]init];
        ctl.index = 1;
        [self.navigationController pushViewController:ctl animated:YES];
    }
    
}


-(void)configData{
    
    switch (self.index) {
        case 0:
        {
            self.navigationItem.title = @"设置";
            NSArray* section0 = @[
                                  @{
                                      @"value":@{GLCustomCellText:@"刘德华",
                                                 GLCustomCellIcon:@"icon",
                                                 @"GLCustomCellIcon.size":[NSValue valueWithCGSize:CGSizeMake(40, 40)],
                                                 GLCustomCellSubText:@"Apple ID,iClound,iTunes与App Store",
                                                 },
                                      @"contolkeys":@[GLCustomCellIcon,@[GLCustomCellText,GLCustomCellSubText],GLCustomCellArrow],
                                      @"identifier":@"7634446687",
                                      @"height":[NSNumber numberWithFloat:66],
                                      },
                                  @{
                                      @"value":@{GLCustomCellText:@"iPhone尚未备份",
                                                 GLCustomCellIcon:@"icon",
                                                 GLCustomCellBadge:@"1",
                                                 @"GLCustomCellBadge.backgroundColor":[UIColor blueColor],
                                                 @"GLCustomCellText.textColor":[UIColor blueColor],
                                                 },
                                      @"contolkeys":@[GLCustomCellIcon,GLCustomCellText,GLCustomCellBadge,GLCustomCellArrow],
                                      @"identifier":@"cell34675",
                                      },
                                  
                                  ];
            NSArray* section1 = @[
                                  @{
                                      @"value":@{GLCustomCellText:@"飞行模式",
                                                 GLCustomCellIcon:@"icon",
                                                 GLCustomCellSwitch:[NSNumber numberWithBool:NO],
                                                 },
                                      @"contolkeys":@[GLCustomCellIcon,GLCustomCellText,GLCustomCellSwitch],
                                      @"identifier":@"cell8324523",
                                      },
                                  @{
                                      @"value":@{GLCustomCellText:@"无线局域网",
                                                 GLCustomCellIcon:@"icon",
                                                 GLCustomCellCatpionText:@"未连接",
                                                 },
                                      @"contolkeys":@[GLCustomCellIcon,GLCustomCellText,GLCustomCellCatpionText,GLCustomCellArrow],
                                      @"identifier":@"cell222",
                                      },
                                  @{
                                      @"value":@{GLCustomCellText:@"蓝牙",
                                                 GLCustomCellIcon:@"icon",
                                                 GLCustomCellCatpionText:@"打开",
                                                 },
                                      @"contolkeys":@[GLCustomCellIcon,GLCustomCellText,GLCustomCellCatpionText,GLCustomCellArrow],
                                      @"identifier":@"cell222",
                                      },
                                  @{
                                      @"value":@{GLCustomCellText:@"蜂窝移动网络",
                                                 GLCustomCellIcon:@"icon",
                                                 GLCustomCellCatpionText:@"",
                                                 },
                                      @"contolkeys":@[GLCustomCellIcon,GLCustomCellText,GLCustomCellCatpionText,GLCustomCellArrow],
                                      @"identifier":@"cell222",
                                      },
                                  @{
                                      @"value":@{GLCustomCellText:@"个人热点",
                                                 GLCustomCellIcon:@"icon",
                                                 GLCustomCellCatpionText:@"关闭",
                                                 },
                                      @"contolkeys":@[GLCustomCellIcon,GLCustomCellText,GLCustomCellCatpionText,GLCustomCellArrow],
                                      @"identifier":@"cell222",
                                      },
                                  ];
            NSArray* section2 = @[
                                  
                                  @{
                                      @"value":@{GLCustomCellText:@"通知",
                                                 GLCustomCellIcon:@"icon",
                                                 GLCustomCellCatpionText:@"",
                                                 },
                                      @"contolkeys":@[GLCustomCellIcon,GLCustomCellText,GLCustomCellCatpionText,GLCustomCellArrow],
                                      @"identifier":@"cell222",
                                      },
                                  @{
                                      @"value":@{GLCustomCellText:@"控制中心",
                                                 GLCustomCellIcon:@"icon",
                                                 GLCustomCellCatpionText:@"",
                                                 },
                                      @"contolkeys":@[GLCustomCellIcon,GLCustomCellText,GLCustomCellCatpionText,GLCustomCellArrow],
                                      @"identifier":@"cell222",
                                      },
                                  @{
                                      @"value":@{GLCustomCellText:@"勿扰模式",
                                                 GLCustomCellIcon:@"icon",
                                                 GLCustomCellCatpionText:@"",
                                                 },
                                      @"contolkeys":@[GLCustomCellIcon,GLCustomCellText,GLCustomCellCatpionText,GLCustomCellArrow],
                                      @"identifier":@"cell222",
                                      },
                                  ];
            NSArray* section3 = @[
                                  
                                  @{
                                      @"value":@{GLCustomCellText:@"通用",
                                                 GLCustomCellIcon:@"icon",
                                                 GLCustomCellBadge:@"2",
                                                 },
                                      @"contolkeys":@[GLCustomCellIcon,GLCustomCellText,GLCustomCellBadge,GLCustomCellArrow],
                                      @"identifier":@"cell333",
                                      },
                                  @{
                                      @"value":@{GLCustomCellText:@"显示与亮度",
                                                 GLCustomCellIcon:@"icon",
                                                 },
                                      @"contolkeys":@[GLCustomCellIcon,GLCustomCellText,GLCustomCellArrow],
                                      @"identifier":@"cell444",
                                      },
                                  @{
                                      @"value":@{GLCustomCellText:@"墙纸",
                                                 GLCustomCellIcon:@"icon",
                                                 },
                                      @"contolkeys":@[GLCustomCellIcon,GLCustomCellText,GLCustomCellArrow],
                                      @"identifier":@"cell444",
                                      },
                                  @{
                                      @"value":@{GLCustomCellText:@"声音与触感",
                                                 GLCustomCellIcon:@"icon",
                                                 },
                                      @"contolkeys":@[GLCustomCellIcon,GLCustomCellText,GLCustomCellArrow],
                                      @"identifier":@"cell444",
                                      },
                                  @{
                                      @"value":@{GLCustomCellText:@"电池",
                                                 GLCustomCellIcon:@"icon",
                                                 },
                                      @"contolkeys":@[GLCustomCellIcon,GLCustomCellText,GLCustomCellArrow],
                                      @"identifier":@"cell444",
                                      },
                                  @{
                                      @"value":@{GLCustomCellText:@"隐私",
                                                 GLCustomCellIcon:@"icon",
                                                 },
                                      @"contolkeys":@[GLCustomCellIcon,GLCustomCellText,GLCustomCellArrow],
                                      @"identifier":@"cell444",
                                      },
                                  
                                  ];
            
            
            
            _myData = @[
                        @{@"sectionTitle":@"",
                          @"sectionData":section0
                          },
                        @{@"sectionTitle":@"",
                          @"sectionData":section1
                          },
                        @{@"sectionTitle":@"",
                          @"sectionData":section2
                          },
                        @{@"sectionTitle":@"",
                          @"sectionData":section3
                          },
                        
                        
                        
                        ];
            break;
        }
        case 1:
        {
            self.navigationItem.title = @"其它";
            NSArray* section1 = @[
                                  @{
                                      @"value":@{GLCustomCellText:@"标题文字1",
                                                 GLCustomCellCatpionText:@"说明文字1"
                                                 },
                                      @"contolkeys":@[GLCustomCellText,GLCustomCellCatpionText],
                                      @"identifier":@"cell1234dg354",
                                      },
                                  @{
                                      @"value":@{GLCustomCellText:@"标题文字2222",
                                                 GLCustomCellCatpionText:@"说明文字2222"
                                                 },
                                      @"contolkeys":@[GLCustomCellText,GLCustomCellCatpionText],
                                      @"identifier":@"cell123jsf354",
                                      },
                                  @{
                                      @"value":@{GLCustomCellText:@"这是一个默认的字符串subtext",
                                                 GLCustomCellIcon:@"icon",
                                                 GLCustomCellSubText:@"subtextsubtextsubtextsubtextsubtext",
                                                 GLCustomCellArrow:@"",
                                                 },
                                      @"contolkeys":@[GLCustomCellIcon,GLCustomCellText,GLCustomCellSubText,GLCustomCellArrow],
                                      @"identifier":@"cel8324523",
                                      @"height":[NSNumber numberWithFloat:60],
                                      },
                                  
                                  @{
                                      @"value":@{GLCustomCellText:@"这是一个默认的字符串",
                                                 },
                                      @"contolkeys":@[GLCustomCellText],
                                      @"identifier":@"cell1adff2354",
                                      },
                                  @{
                                      @"value":@{GLCustomCellText:@"这是一个默认的字符串badge",
                                                 GLCustomCellIcon:@"icon",
                                                 GLCustomCellBadge:@"34",
                                                 GLCustomCellArrow:@"",
                                                 },
                                      @"contolkeys":@[GLCustomCellIcon,GLCustomCellText,GLCustomCellBadge,GLCustomCellArrow],
                                      @"identifier":@"cell1sfg354",
                                      },
                                  @{
                                      @"value":@{GLCustomCellText:@"这是一个默认的字符串",
                                                 GLCustomCellRadio:[NSNumber numberWithBool:YES]
                                                 },
                                      @"contolkeys":@[GLCustomCellText,GLCustomCellRadio,GLCustomCellArrow],
                                      @"identifier":@"cell15456s354",
                                      }
                                  ];
            NSArray* section2 = @[@{
                                      @"value":@{GLCustomCellText:@"标题文字1",
                                                 GLCustomCellCatpionText:@"说明文字1",
                                                 GLCustomCellIcon:[UIImage imageNamed:@"icon.png"]
                                                 },
                                      @"contolkeys":@[GLCustomCellText,GLCustomCellCatpionText,GLCustomCellIcon,GLCustomCellArrow],
                                      @"identifier":@"cell1aagfdgdii12354",
                                      },
                                  @{
                                      @"value":@{GLCustomCellText:@"这是一个默认的字符串badge",
                                                 GLCustomCellBadge:@"boys",
                                                 GLCustomCellCatpionText:@"hahahaha",
                                                 GLCustomCellArrow:@"",
                                                 },
                                      @"contolkeys":@[GLCustomCellText,GLCustomCellCatpionText,GLCustomCellBadge,GLCustomCellArrow],
                                      @"identifier":@"cell131234d12354",
                                      },
                                  @{
                                      @"value":@{GLCustomCellText:@"badge",
                                                 GLCustomCellBadge:@"boys",
                                                 GLCustomCellCatpionText:@"hahahaha",
                                                 GLCustomCellIcon:@"icon",
                                                 },
                                      @"contolkeys":@[GLCustomCellIcon,GLCustomCellText,GLCustomCellCatpionText,GLCustomCellBadge],
                                      @"identifier":@"cell5jsdfgrq4",
                                      },
                                  @{
                                      @"value":@{GLCustomCellText:@"呵呵",
                                                 GLCustomCellCatpionText:@"",
                                                 GLCustomCellButton:@"你敢点我吗",
                                                 @"GLCustomCellButton.imageName":@"icon",
                                                 },
                                      @"contolkeys":@[GLCustomCellText,GLCustomCellButton,GLCustomCellCatpionText,GLCustomCellArrow],
                                      @"identifier":@"celdagdhae12354",
                                      },
                                  @{
                                      @"value":@{GLCustomCellText:@"标题文字22",
                                                 GLCustomCellCatpionText:@"说明文字2",
                                                 GLCustomCellIcon:[UIImage imageNamed:@"icon.png"]
                                                 },
                                      @"contolkeys":@[GLCustomCellText,GLCustomCellCatpionText,GLCustomCellIcon,GLCustomCellArrow],
                                      @"identifier":@"cell1asdgh",
                                      }];
            NSArray* section3 = @[
                                  @{
                                      @"value":@{GLCustomCellText:@"标题文字",
                                                 },
                                      @"contolkeys":@[GLCustomCellText,GLCustomCellArrow],
                                      @"identifier":@"cell1kdsbv5354",
                                      },
                                  @{
                                      @"value":@{GLCustomCellText:@"标题文字",
                                                 },
                                      @"contolkeys":@[GLCustomCellText,GLCustomCellArrow],
                                      @"identifier":@"cell1kdsbv5354",
                                      }
                                  ];
            
            NSArray* section4 = @[
                                  @{
                                      @"value":@{GLCustomCellText:@"文字hlkjhfjkasdflkasdf标题",
                                                 GLCustomCellCatpionText:@"说明文字说明文字说明文字说明文字",
                                                 GLCustomCellIcon:[UIImage imageNamed:@"icon.png"]
                                                 },
                                      @"contolkeys":@[GLCustomCellText,GLCustomCellCatpionText,GLCustomCellIcon,GLCustomCellArrow],
                                      @"identifier":@"cel5yjmdbsf4",
                                      },
                                  @{
                                      @"value":@{GLCustomCellText:@"标题文字标题文字标题标题文字标题文字标题标题文字标题文字标题标题文字标题文字标题",
                                                 GLCustomCellCatpionText:@"说明文字",
                                                 GLCustomCellIcon:[UIImage imageNamed:@"icon.png"]
                                                 },
                                      @"contolkeys":@[GLCustomCellText,GLCustomCellCatpionText,GLCustomCellIcon],
                                      @"identifier":@"celljhgfi945d354",
                                      }
                                  ];
            NSArray* section5 = @[
                                  @{
                                      @"value":@{GLCustomCellText:@"标题文字",
                                                 GLCustomCellSwitch:[NSNumber numberWithBool:YES]
                                                 },
                                      @"contolkeys":@[GLCustomCellText,GLCustomCellSwitch],
                                      @"identifier":@"cell1gadfsrtey54",
                                      },
                                  @{
                                      @"value":@{GLCustomCellText:@"标题文字",
                                                 GLCustomCellSwitch:[NSNumber numberWithBool:NO],
                                                 @"GLCustomCellSwitch.tintColor":[UIColor redColor],
                                                 @"GLCustomCellSwitch.onTintColor":[UIColor redColor],
                                                 },
                                      @"contolkeys":@[GLCustomCellText,GLCustomCellSwitch],
                                      @"identifier":@"celadfgttrh354",
                                      }
                                  
                                  ];
            
            NSArray* section6 = @[
                                  @{
                                      @"value":@{GLCustomCellText:@"用户名",
                                                 @"GLCustomCellInput.placeholder":@"请输入用户名",
                                                 },
                                      @"contolkeys":@[GLCustomCellText,GLCustomCellInput],
                                      @"identifier":@"cell1jffgdrtedg4",
                                      },
                                  @{
                                      @"value":@{GLCustomCellText:@"密码",
                                                 @"GLCustomCellInput.placeholder":@"请输入密码",
                                                 @"GLCustomCellInput.secureTextEntry":[NSNumber numberWithBool:YES],
                                                 },
                                      @"contolkeys":@[GLCustomCellText,GLCustomCellInput],
                                      @"identifier":@"cell1asd4534fq354",
                                      },
                                  @{
                                      @"value":@{GLCustomCellText:@"家庭地址",
                                                 @"GLCustomCellInput.placeholder":@"请输入地址",
                                                 },
                                      @"contolkeys":@[GLCustomCellInput,GLCustomCellText],
                                      @"identifier":@"cell1asd4534fq354",
                                      },
                                  @{
                                      @"value":@{GLCustomCellText:@"用户名",
                                                 @"GLCustomCellText.limitWordNumber":[NSNumber numberWithInteger:4],
                                                 @"GLCustomCellInput.placeholder":@"请输入用户名-左对齐",
                                                 },
                                      @"contolkeys":@[GLCustomCellText,GLCustomCellInput],
                                      @"identifier":@"cellfghjsidhfg",
                                      },
                                  @{
                                      @"value":@{GLCustomCellText:@"密码",
                                                 @"GLCustomCellText.limitWordNumber":[NSNumber numberWithInteger:4],
                                                 @"GLCustomCellInput.placeholder":@"请输入密码-左对齐",
                                                 @"GLCustomCellInput.secureTextEntry":[NSNumber numberWithBool:YES],
                                                 },
                                      @"contolkeys":@[GLCustomCellText,GLCustomCellInput],
                                      @"identifier":@"cellfghjsidhfg",
                                      },
                                  @{
                                      @"value":@{GLCustomCellText:@"家庭地址",
                                                 @"GLCustomCellText.limitWordNumber":[NSNumber numberWithInteger:4],
                                                 @"GLCustomCellInput.placeholder":@"请输入地址-左对齐",
                                                 },
                                      @"contolkeys":@[GLCustomCellText,GLCustomCellInput],
                                      @"identifier":@"cellfghjsidhfg",
                                      
                                      },
                                  @{
                                      @"value":@{GLCustomCellSubText:@"用户名",
                                                 @"GLCustomCellInput.placeholder":@"请输入用户名",
                                                 },
                                      @"contolkeys":@[@[GLCustomCellSubText,GLCustomCellInput]],
                                      @"identifier":@"ghjdhfggfhsdg",
                                      @"height":@74,
                                      },
                                  @{
                                      @"value":@{GLCustomCellSubText:@"密码",
                                                 @"GLCustomCellInput.placeholder":@"请输入密码",
                                                 @"GLCustomCellInput.secureTextEntry":[NSNumber numberWithBool:YES],
                                                 },
                                      @"contolkeys":@[@[GLCustomCellSubText,GLCustomCellInput]],
                                      @"identifier":@"cellsafghjsewryidhfg",
                                      @"height":@74,
                                      },
                                  ];
            
            NSArray* section7 = @[
                                  @{
                                      @"value":@{GLCustomCellCenterText:@"登录",
                                                 },
                                      @"contolkeys":@[GLCustomCellCenterText],
                                      @"identifier":@"asdgerwhsdf",
                                      },
                                  
                                  ];
            NSArray* section8 = @[
                                  @{
                                      @"value":@{GLCustomCellCenterText:@"退出",
                                                 },
                                      @"contolkeys":@[GLCustomCellCenterText],
                                      @"identifier":@"celhdfgbt4",
                                      },
                                  ];
            NSArray* section9 = @[
                                  @{
                                      @"value":@{GLCustomCellText:@"这是一个选项1",
                                                 GLCustomCellRadio:[NSNumber numberWithBool:YES]
                                                 },
                                      @"contolkeys":@[GLCustomCellText,GLCustomCellRadio],
                                      @"identifier":@"cellraGLCustomCellRadio",
                                      },
                                  @{
                                      @"value":@{GLCustomCellText:@"这是一个选项2",
                                                 GLCustomCellRadio:[NSNumber numberWithBool:NO]
                                                 },
                                      @"contolkeys":@[GLCustomCellText,GLCustomCellRadio],
                                      @"identifier":@"cellraGLCustomCellRadio",
                                      },
                                  @{
                                      @"value":@{GLCustomCellText:@"这是一个选项3",
                                                 GLCustomCellRadio:[NSNumber numberWithBool:NO]
                                                 },
                                      @"contolkeys":@[GLCustomCellText,GLCustomCellRadio],
                                      @"identifier":@"cellraGLCustomCellRadio",
                                      },
                                  @{
                                      @"value":@{GLCustomCellText:@"这是一个选项4",
                                                 GLCustomCellRadio:[NSNumber numberWithBool:NO]
                                                 },
                                      @"contolkeys":@[GLCustomCellText,GLCustomCellRadio],
                                      @"identifier":@"cellraGLCustomCellRadio",
                                      },
                                  @{
                                      @"value":@{GLCustomCellText:@"这是一个选项5",
                                                 GLCustomCellRadio:[NSNumber numberWithBool:NO]
                                                 },
                                      @"contolkeys":@[GLCustomCellText,GLCustomCellRadio],
                                      @"identifier":@"cellraGLCustomCellRadio",
                                      },
                                  
                                  ];
            
            
            
            _myData = @[
                        @{@"sectionTitle":@"文本域，输入框",
                          @"sectionData":section6},
                        @{@"sectionTitle":@"带说明的列表项",
                          @"sectionData":section1},
                        @{@"sectionTitle":@"带图标、说明的列表项",
                          @"sectionData":section2},
                        @{@"sectionTitle":@"带跳转的列表项",
                          @"sectionData":section3},
                        @{@"sectionTitle":@"带图标、说明、跳转的列表项",
                          @"sectionData":section4},
                        @{@"sectionTitle":@"开关",
                          @"sectionData":section5},
                        @{@"sectionTitle":@"选项",
                          @"sectionData":section9},
                        @{@"sectionTitle":@"",
                          @"sectionData":section7},
                        @{@"sectionTitle":@"",
                          @"sectionData":section8},
                        ];
            
            break;
        }
        case 2:
        {
            break;
        }
        case 3:
        {
            break;
        }
        case 4:
        {
            break;
        }
        case 5:
        {
            break;
        }
        case 6:
        {
            break;
        }
        case 7:
        {
            break;
        }
        case 8:
        {
            break;
        }
        default:
        {
            
        }
    }
    
}

-(GLForm*)getFormData{
    GLForm* form = [GLForm formWithTag:@""];
    for (NSDictionary* section in _myData) {
        NSString* sectionTitle = section[@"sectionTitle"];
        GLFormSection* formSection = [GLFormSection formSectionWithTag:sectionTitle];
        NSArray* rows = section[@"sectionData"];
        
        for (NSDictionary* row in rows) {
            NSString* identifier = row[@"identifier"];
            NSArray* keys = row[@"contolkeys"];
            NSDictionary* values = row[@"value"];
            NSNumber* height = row[@"height"];
            
            GLFormRow * formRow = [GLFormRow formRowByComponentKeys:keys withTag:identifier];
            
            [formRow addConfigValuesByDictionary:values];
            if (height) {
                formRow.rowHeight = [height floatValue];
            }
            [formSection addFormRow:formRow];
            if (self.index == 1) {
                formSection.HeaderHeight = 44;
            }
        }
        [form addFormSection:formSection];
        
    }
    
    GLFormSection* subSectioin = [GLFormSection formSectionWithTag:@"test"];
    subSectioin.HeaderHeight =44 ;
    for (NSInteger i = 1;i<= 6;i++) {
        GLFormRow * formRow = [GLFormRow formRowWithCustomCellIdentifier:[NSString stringWithFormat:@"GLCustomCellIdentifierCell%ld",i]];
        NSDictionary* dict =  @{
                                @"icon":@"icon",
                                @"title":[NSString stringWithFormat:@"cell测试:%ld",i],
                                @"sub":@"nothing",
                                };
        
        [formRow updateCellByModel:dict];
        
        [subSectioin addFormRow:formRow];
    }
    [form addFormSection:subSectioin];
    return form;
}

@end
